 ///
 /// @file    poly2.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-14 15:14:34
 ///
 
#include <iostream>
using std::cout;
using std::endl;

class Base
{
public:
	virtual
	void display()
	{
		cout << "Base::display()" << endl;
	}
};

class Child1 : public Base
{
public:
#if 1
	void display()
	{
		cout << "Child1::display()" << endl;
	}
#endif

	void print()
	{
		cout << "Child1::print()" << endl;
	}
};

class Child2 : public Base
{
public:
	void display()
	{
		cout << "Child2::display()" << endl;
	}
private:
	int _ia;
};

void display(Base * pbase)
{
	pbase->display();
}

int main(void)
{
	Base base;
	Child1 child1;
	Child2 child2;
	child1.display();//通过对象名去调用时，并不表现出
					//虚函数的特性,跟调用非虚函数是一样的
	child1.print();//
	child1.Base::display();

	Base * pbase = &child2;
	pbase->display();//当基类指针或者引用指向派生类对象，
					//并通过基类指针调用虚函数，
					//此时才发挥虚函数的作用
	Base & ref = child2;
	ref.display();
}
